package com.cloud.flowbusdemo.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import com.cloud.flowbusdemo.R
import com.cloud.flowbusdemo.databinding.FragmentMainBinding

private const val ARG_PARAM_NAME = "name"
private const val ARG_PARAM_AGE = "age"

/**
 * @auth: njb
 * @date: 2024/9/17 18:46
 * @desc: 描述
 */
class MainFragment : Fragment() {
    private lateinit var binding: FragmentMainBinding
    private var name: String? = null
    private var age: Int? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            name = it.getString(ARG_PARAM_NAME)
            age = it.getInt(ARG_PARAM_AGE)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentMainBinding.inflate(layoutInflater)
        initView()
        return binding.root
    }

    private fun initView() {
        binding.btnToSecondFragment.setOnClickListener(View.OnClickListener { v ->
            val args: Bundle = Bundle().apply {
                this.putString(ARG_PARAM_NAME, "哈哈")
                this.putInt(ARG_PARAM_AGE, 25)
            }
            Navigation.findNavController(v)
                .navigate(R.id.action_mainFragment_to_secondFragment, args)
        })
        binding.btnToMineFragment.setOnClickListener{v ->
            val bundle: Bundle = MainFragmentArgs("小当家",30).toBundle()
             Navigation.findNavController(v).navigate(R.id.action_mainFragment_to_mineFragment,bundle)
        }
    }


}